home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
DesktopDoubler
/
NubApp
/
Menu.cc
< prev
next >
Wrap
Text File
|
1999-06-23
|
6KB
|
482 lines
#define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
#define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
#include "DebugUtils.h"
#include <ctype.h>
#include <Devices.h>
#include <string.h>
#include "Main.h"
#include "Menu.h"
#include "Notice.h"
#include "QDUtils.h"
#include "StringUtils.h"
#include "Version.h"
#include "Window.h"
extern WindowManager *gWindowManager;
extern MenuManager *gMenuManager;
void BaseMenuManager::DoAddMenu(Menu *menu)
{
HandleAddMenu(menu);
}
void BaseMenuManager::DoMenuUpdates(void)
{
BaseMenuObject *mobj;
Window *win;
Boolean redraw;
mobj = fMenuList.GetFirst();
while(mobj != NULL)
{
HandleMenuUpdate(mobj->fMenuObject);
mobj = mobj->next;
}
redraw = false;
win = gWindowManager->DoGetFrontWindow();
if (win && ((win->fFlags & (kDialog | kModal)) == (kDialog | kModal)))
{
// Enable Moveable Modal Dialog state
mobj = fMenuList.GetFirst();
while(mobj != NULL)
{
if (mobj->fMenuObject->DoSetDisableState(true))
redraw = true;
mobj = mobj->next;
}
}
else
{
// Disable Moveable Modal Dialog state
mobj = fMenuList.GetFirst();
while(mobj != NULL)
{
if (mobj->fMenuObject->DoSetDisableState(false))
redraw = true;
mobj = mobj->next;
}
}
if (redraw)
::DrawMenuBar();
}
void BaseMenuManager::DoSelect(UInt32 menu,UInt32 item)
{
Menu *mobj;
mobj = DoGetMenu(menu);
if (mobj != NULL)
HandleSelect(mobj,item);
::HiliteMenu(0);
}
void BaseMenuManager::DoWindowNotice(Window *window,Boolean isBeingAdded)
{
BaseMenuObject *mobj;
mobj = fMenuList.GetFirst();
while(mobj != NULL)
{
HandleWindowNotice(mobj->fMenuObject,window,isBeingAdded);
mobj = mobj->next;
}
}
void BaseMenuManager::DoWindowActivation(Window *window,Boolean isBeingActivated)
{
BaseMenuObject *mobj;
mobj = fMenuList.GetFirst();
while(mobj != NULL)
{
HandleWindowActivation(mobj->fMenuObject,window,isBeingActivated);
mobj = mobj->next;
}
}
Menu *BaseMenuManager::DoGetMenu(UInt32 menuID)
{
return HandleGetMenu(menuID);
}
void BaseMenuManager::HandleAddMenu(Menu *menu)
{
BaseMenuObject *obj;
obj = new BaseMenuObject;
if (obj != NULL)
{
obj->fMenuID = menu->fMenu[0]->menuID;
obj->fMenuObject = menu;
fMenuList.Append(obj);
::InsertMenu(menu->fMenu,0);
}
}
void BaseMenuManager::HandleMenuUpdate(Menu *menu)
{
menu->DoUpdate();
}
void BaseMenuManager::HandleSelect(Menu *menu,UInt32 item)
{
menu->DoSelect(item);
}
void BaseMenuManager::HandleWindowNotice(Menu *menu,Window *window,Boolean isBeingAdded)
{
menu->DoWindowNotice(window,isBeingAdded);
}
void BaseMenuManager::HandleWindowActivation(Menu *menu,Window *window,Boolean isBeingActivated)
{
menu->DoWindowActivation(window,isBeingActivated);
}
Menu *BaseMenuManager::HandleGetMenu(UInt32 menuID)
{
BaseMenuObject *obj;
obj = fMenuList.GetFirst();
while(obj && (obj->fMenuID != menuID))
obj = obj->next;
return obj ? obj->fMenuObject : NULL;
}
BaseMenu::BaseMenu(UInt32 menuID)
{
fMenu = ::GetMenu(menuID);
if (fMenu != NULL)
{
fFlags = 0;
gMenuManager->DoAddMenu(this);
}
}
void BaseMenu::DoUpdate(void)
{
HandleUpdate();
}
void BaseMenu::DoSelect(UInt32 item)
{
HandleSelect(item);
}
Boolean BaseMenu::DoSetDisableState(Boolean isBeingDisabled)
{
if (isBeingDisabled)
{
if (!(fFlags & kDisabled))
{
fFlags |= kDisabled;
HandleSetDisableState(isBeingDisabled);
return true;
}
}
else
{
if (fFlags & kDisabled)
{
fFlags &= ~kDisabled;
HandleSetDisableState(isBeingDisabled);
return true;
}
}
return false;
}
void BaseMenu::DoWindowNotice(Window *window,Boolean isBeingAdded)
{
HandleWindowNotice(window,isBeingAdded);
}
void BaseMenu::DoWindowActivation(Window *window,Boolean isBeingActivated)
{
HandleWindowActivation(window,isBeingActivated);
}
void BaseMenu::HandleUpdate(void)
{
}
void BaseMenu::HandleSelect(UInt32 item)
{
}
void BaseMenu::HandleSetDisableState(Boolean isBeingDisabled)
{
if (isBeingDisabled)
DisableItem(fMenu,0);
else
EnableItem(fMenu,0);
}
void BaseMenu::HandleWindowNotice(Window *window,Boolean isBeingAdded)
{
}
void BaseMenu::HandleWindowActivation(Window *window,Boolean isBeingActivated)
{
}
AppleMenu::AppleMenu(void) : BaseMenu(256)
{
AppendResMenu(fMenu,'DRVR');
}
void AppleMenu::HandleSelect(UInt32 item)
{
QDContext context;
Str255 name;
switch(item)
{
case 1:
ShowAboutBox();
break;
default:
GetMenuItemText(fMenu,item,name);
OpenDeskAcc(name);
break;
}
}
void AppleMenu::HandleSetDisableState(Boolean isBeingDisabled)
{
if (isBeingDisabled)
DisableItem(fMenu,1);
else
EnableItem(fMenu,1);
}
void AppleMenu::ShowAboutBox(void)
{
Str31 vnum,vers;
Str255 name;
OSStatus err;
// Get app name from Apple menu.
GetMenuItemText(fMenu,1,name);
while((name[0] > 0) && !isspace(name[1]))
memmove(&name[1],&name[2],--name[0]);
while((name[0] > 0) && isspace(name[1]))
memmove(&name[1],&name[2],--name[0]);
while((name[0] > 0) && ((char)name[name[0]] == (char)'…'))
name[0] -= 1;
// Get version from vers resource.
err = GetNumVersionPString(vnum);
if (err == noErr)
{
pstrcpy(vers,"\pversion: ");
pstrcat(vers,vnum);
}
else
vers[0] = 0;
PostNotice(kAlertNoteAlert,name,vers);
}
FileMenu::FileMenu(void) : BaseMenu(257)
{
}
void FileMenu::HandleSelect(UInt32 item)
{
switch(item)
{
default:
InitiateAppQuit();
break;
}
}
EditMenu::EditMenu(void) : BaseMenu(258)
{
}
void EditMenu::HandleSelect(UInt32 item)
{
Window *win;
win = gWindowManager->DoGetFrontWindow();
if (win != NULL)
{
switch(item)
{
case 1:
win->DoSetParam('undo',0);
break;
case 3:
win->DoSetParam('cut ',0);
break;
case 4:
win->DoSetParam('copy',0);
break;
case 5:
win->DoSetParam('past',0);
break;
case 6:
win->DoSetParam('clea',0);
break;
}
}
}